package com.example.demo.config;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.example.demo.context.SysContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Component
public class DateConfig implements MetaObjectHandler {

    /**
     * 处理新增时的字段
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName("createTime", DateUtil.date(),metaObject);
        setFieldValByName("createBy", SysContext.get(),metaObject);
    }

    /**
     * 处理更新时字段
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("updateTime", DateUtil.date(),metaObject);
        setFieldValByName("updateBy", SysContext.get(),metaObject);
    }
}
